/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerbean;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import model.dao.ComplaintFacadeLocal;
import model.entities.Complaint;

/**
 *
 * @author NgocNH
 */
@ManagedBean
@RequestScoped
public class complaintBean {
    @EJB
    private ComplaintFacadeLocal complaintFacade;
    private List<Complaint> complaintList;
    private Complaint selectedComplain;
    private Complaint[] selectedComplaints;
    private Date datee;

    /** Creates a new instance of complaintBean */
    public complaintBean() {
        complaintList = new ArrayList<Complaint>();
    }
    
    public List<Complaint> getAllConplaint() {
        complaintList = complaintFacade.findAll();
        
        for (Complaint complaint : complaintList) {
            try {
                Complaint com = new Complaint();
                com = complaint;
                DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                Date date = (Date)format.parse(complaint.getDateAdded().toString());
                com.setDateAdded(date);
                complaintList.remove(complaint);
                complaintList.add(com);
                this.datee = date;
            } catch (ParseException ex) {
                Logger.getLogger(complaintBean.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        return complaintList;
    }
    
    public Date getDatee() {
        return datee;
    }
    
    public Complaint getSelectedComplaint() {
        return selectedComplain;
    }
    
    public void setSelectedComplaint(Complaint selectedComplaint) {
        this.selectedComplain = selectedComplaint;
    }
}
